package com.ln.asset.core.controller.api;

import com.ln.asset.common.result.R;
import com.ln.asset.core.pojo.AssetInfo;
import com.ln.asset.core.pojo.Transformation;
import com.ln.asset.core.service.TransformationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created with Intellij IDEA.
 *
 * @Author: 乔燕茹
 * @Date: 2022/04/28/21:183
 */
@Api(tags = "申请资产转移")
@RestController
@RequestMapping("/api/core/transformation")
@Slf4j
public class TransformationController {
    @Resource
    private TransformationService transformationService;

    @ApiOperation("申请资产转移")
    @PostMapping("/applyTransfor")
    public R applyTransfor(@ApiParam(value = "Transformation对象",required = true)
                           @RequestBody Transformation transformation,
                           @RequestParam(name = "aid",required = false) String aid){
        System.out.println("结合结合结合======="+aid);
        String[] split = aid.split(",");
        List<String> strings = Arrays.asList(split);
        List<Integer> list = new ArrayList<>();
        for (String string : strings) {
            int i = Integer.parseInt(string);
            list.add(i);
        }
        try {
            transformationService.applyTransfor(transformation);
            //添加中间表
            transformationService.applyTransforZhong(transformation.getTId(),list);
            return R.ok().message("申请成功");
        }catch (Exception e){
            e.printStackTrace();
            return R.error().message("申请失败");
        }
    }
}
